home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
OTHER_LA
/
YERK__
/
TOOLBOX_
/
INTERVAL
< prev
next >
Wrap
Text File
|
1990-12-14
|
1KB
|
52 lines
\ interval - interval timer stuff
\ 12/14/84 cbd Version 1
\ 10/15/85 cdn Fixed print: method in Timer
\ 1/31/87 rfl added clear:
\ 6/13/89 rfl added pause
\ 12/12/90 rfl modified when: to not depend on events...looks at global 'ticks'
\ also changed pause and wait to >= compares
Decimal
\ define an interval timer class
:CLASS Timer <Super Object
Var Ticks \ store system ticks=60ths
Int On \ true = timing
\ ( -- ticks ) return system ticks
:M WHEN: global ticks @ ;M
\ start timing an interval
:M START: when: self put: ticks 1 put: on ;M
\ stop the clock, and replace ticks with the interval
:M STOP: when: self get: ticks - put: ticks clear: on ;M
\ ( -- secs*60 ) get the current value of the clock, but keep timing if on
:M GET: get: on
IF when: self get: ticks -
ELSE get: ticks THEN ;M
\ print the current value of the timer, in seconds and hundredths
:M PRINT: get: self 60 /mod 3 .R $ 2e emit 100 * 60 /
2 .R ." Seconds " ;M
:M CLEAR: clear: on clear: ticks ;M
;CLASS
Timer sysTimer \ create an instance of Timer
\ ( -- f OR key t ) listen to event queue, true if key event
: ?Key next: fEvent ;
\ general purpose pause where time is in 1/60ths of second - process events
timer pTimer
: pause { time -- } start: pTimer
BEGIN next: fevent IF 2drop THEN get: pTimer time >= UNTIL ;
\ same as pause, but don't process events
: wait { time -- } start: pTimer
BEGIN get: pTimer time >= UNTIL ;